package com.googlecode.player.view.specialmaterials
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	import mx.controls.Alert;
	
	import org.papervision3d.materials.MovieMaterial;

	public class ControlledMovieMaterial extends MovieMaterial
	{
		
		protected var _transport:Transport;
		
		public function ControlledMovieMaterial(movieAsset:DisplayObject=null, transparent:Boolean=false, animated:Boolean=false, precise:Boolean=false, rect:Rectangle=null)
		{
			
			
			_transport = new Transport();
			_transport._play.stop();
			_transport._stop.stop();
			_transport.x = (movieAsset.width / 2) - (_transport.width / 2);
			_transport.y = (movieAsset.height - _transport.height) - 5;
			
			_transport._play.addEventListener(MouseEvent.CLICK, onPlay);
			_transport._stop.addEventListener(MouseEvent.CLICK, onStop);
			_transport._play.addEventListener(MouseEvent.MOUSE_OVER, onPlayOver);
			_transport._stop.addEventListener(MouseEvent.MOUSE_OVER, onStopOver);
			_transport._play.addEventListener(MouseEvent.MOUSE_OUT, onPlayOut);
			_transport._stop.addEventListener(MouseEvent.MOUSE_OUT, onStopOut);
			
			(movieAsset as MovieClip).addChild(_transport);
			
			(movieAsset as MovieClip).stop();
			
			super(movieAsset, transparent, true, precise, rect);
			
			this.animated = true;
			this.interactive = true;
		
		}
		
		protected function onPlay(evt:MouseEvent):void
		{
			(this.movie as MovieClip).play();
		}
		
		protected function onStop(evt:MouseEvent):void
		{
			(this.movie as MovieClip).stop();
		}
		
		protected function onPlayOver(evt:MouseEvent):void
		{
			_transport._play.gotoAndStop("over");
		}
		
		protected function onStopOver(evt:MouseEvent):void
		{
			_transport._stop.gotoAndStop("over");
		}
		
		protected function onPlayOut(evt:MouseEvent):void
		{
			_transport._play.gotoAndStop("up");
		}
		
		protected function onStopOut(evt:MouseEvent):void
		{
			_transport._stop.gotoAndStop("up");
		}
		
	}
}